{% extends "_layout.html" %}
{% import "component/statistics.njk" as statistics %}

{# 样式代码 #}
{% block style %}
<title>发布作业</title>
<link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
<style type="text/css">
    .mui-content{padding-bottom: 65px;}
    .mui-content>.mui-table-view:first-child{margin: 0;}
    .mui-table-view-cell{ padding: 16px 15px;}
    .mui-table-view-cell>a:not(.mui-btn){margin: -16px -15px;}
</style>
{% endblock %}

{# bodyd代码#}
{% block body %}
<div class="mui-content">
    <!--作业名称-->
    <form class="mui-input-group mb-input-group">
        <div class="mui-input-row mb-input-row">
            <label>作业名称</label>
            <input class="homework-name" id="homeworkName" type="text" placeholder="请输入作业名称" value="">
        </div>
        <div class="mui-input-row mb-input-row">
            <label>发布时间</label>
            <button id='result' data-options='{}' class="btn mui-btn mui-btn-block">立即发布</button>
            <i class="mui-icon mui-icon-arrowright"></i>
        </div>
        <div class="mui-input-row mb-input-row">
            <label>截止时间</label>
            <button id='result1' data-options='{}' class="btn1 mui-btn mui-btn-block">截止时间</button>
            <i class="mui-icon mui-icon-arrowright"></i>
        </div>
        <div id="release" class="mb-input-submit">
            <input class="homework-submit" type="submit" value="立即发布" />
        </div>
    </form>
</div>
{% endblock %}

{#js代码#}
{% block js %}
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/mui.picker.min.js"></script>
<script type="text/javascript">
    (function($) {
        //发布时日返回结果
        $.init();
        var result = $('#result')[0];
        var result1 = $('#result1')[0];
        var btns = $('.btn');
        var btns1 = $('.btn1');
        btns.each(function(i, btn) {
            btn.addEventListener('tap', function() {
                var _self = this;
                if(_self.picker) {
                    _self.picker.show(function (rs) {
                        result.innerText = rs.text;
                    });
                } else {
                    var optionsJson = this.getAttribute('data-options') || '{}';
                    var options = JSON.parse(optionsJson);
                    var id = this.getAttribute('id');
                    _self.picker = new $.DtPicker(options);
                    _self.picker.show(function(rs) {
                        result.innerText = rs.text;
                    });
                }

            }, false);
        });
        //截止日期返回结果
        btns1.each(function(i, btn1) {
            btn1.addEventListener('tap', function() {
                var _self = this;
                if(_self.picker) {
                    _self.picker.show(function (rs) {
                        result1.innerText = rs.text;
                    });
                } else {
                    var optionsJson = this.getAttribute('data-options') || '{}';
                    var options = JSON.parse(optionsJson);
                    var id = this.getAttribute('id');
                    _self.picker = new $.DtPicker(options);
                    _self.picker.show(function(rs) {
                        result1.innerText = rs.text;
                    });
                }

            }, false);
        });
    })(mui);

    //当前日期
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "月";
        var seperator2 = "日作业";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = strDate;
        }
        var currentdate =month + seperator1 + strDate + seperator2;
        return currentdate;
    }
    document.getElementById("homeworkName").value = getNowFormatDate();

</script>

<script>


    let createDate = result.innerText;

    $(".homework-submit").on('click',function(){
        event.preventDefault();
        let titlename = $('#homeworkName').val();
        let teacherClazzId = sessionStorage.getItem('teacherClazzId');
        let clazzId = sessionStorage.getItem('clazzId');
        let typeJob = sessionStorage.getItem('typeJob');
        if(createDate == '立即发布'){
            let date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth()+1;
            let day = date.getDate();
            let hours = date.getHours();
            let minutes = date.getMinutes();

            createDate = year+'-'+month+'-'+day+' '+hours+':'+minutes;
        }else {
            createDate = result.innerText;
        }

        mui.post('/release',{
            typeJob:typeJob,
            teacherClazzId:teacherClazzId,
            clazzId:clazzId,
            checkDate:result1.innerText,
            createDate:createDate,
            teacherQuestionIds:sessionStorage.getItem('dataid'),
            pushStatus:2,
            name:titlename,
            studentIds:sessionStorage.getItem('studentIds'),
        },function(data){
            if(data.code != 200){
                mui.toast('发布失败');
            }else{
                sessionStorage.removeItem('dataid');
                mui.toast('发布成功');
                window.location.replace('index');
            }
        },'json');
    });


</script>

<!--flotdemo-->
{% endblock %}
